package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.serve.vo.DeviceDataGraphVo;
import com.zzyl.serve.vo.FamilymemberVo;
import com.zzyl.serve.vo.MemberVo;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;
import java.util.List;
import com.zzyl.serve.domain.FamilyMember;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 老人家属Mapper接口
 * 
 * @author itheima
 * @date 2025-03-12
 */
@Mapper
public interface FamilyMemberMapper extends BaseMapper<FamilyMember>
{
    /**
     * 查询老人家属
     * 
     * @param id 老人家属主键
     * @return 老人家属
     */
    public FamilyMember selectFamilyMemberById(Long id);

    /**
     * 查询老人家属列表
     * 
     * @param familyMember 老人家属
     * @return 老人家属集合
     */
    public List<FamilyMember> selectFamilyMemberList(FamilyMember familyMember);

    /**
     * 新增老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int insertFamilyMember(FamilyMember familyMember);

    /**
     * 修改老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int updateFamilyMember(FamilyMember familyMember);

    /**
     * 删除老人家属
     * 
     * @param id 老人家属主键
     * @return 结果
     */
    public int deleteFamilyMemberById(Long id);

    /**
     * 批量删除老人家属
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFamilyMemberByIds(Long[] ids);

    @Select("select DATE_FORMAT(alarm_time, '%H:00') as dateTime ,avg(data_value) as dataValue from device_data\n" +
            "    where alarm_time between #{startLocalDateTime} and #{endLocalDateTime} and function_id = #{functionId} and iot_id = #{iotId}\n" +
            "    group by HOUR(alarm_time);")
    List<DeviceDataGraphVo> queryDeviceDataListByDay(@Param("startLocalDateTime") LocalDateTime startLocalDateTime,@Param("endLocalDateTime") LocalDateTime endLocalDateTime,@Param("iotId") String iotId,@Param("functionId") String functionId);

    @Select("-- 查询指定时间范围内，按天分组的平均 data_value 值\n" +
            "SELECT \n" +
            "    DATE_FORMAT(alarm_time, '%m:%d') AS dateTime,   \n" +
            "    AVG(data_value) AS dataValue               \n" +
            "FROM \n" +
            "    device_data                                    \n" +
            "WHERE \n" +
            "    alarm_time BETWEEN #{startLocalDateTime} AND #{endLocalDateTime} \n" +
            "    AND function_id = #{functionId}                \n" +
            "    AND iot_id = #{iotId}                         \n" +
            "GROUP BY \n" +
            "    DATE_FORMAT(alarm_time, '%m:%d');              \n")
    List<DeviceDataGraphVo> queryDeviceDataListByWeek(@Param("startLocalDateTime")LocalDateTime startLocalDateTime, @Param("endLocalDateTime")LocalDateTime endLocalDateTime,@Param("iotId")  String iotId,@Param("functionId") String functionId);

    //从数据库中查询 id ,familyMemberId elderId  elderName

    List<FamilymemberVo> selectmyFamilyMember(@Param("id")Long id);

    List<MemberVo> getPage(@Param("id")Long id);
}
